

/********************************************************************/
/*                                                                  */ 
/* Create graphs showing mean levels for outcome variables          */
/*                                                                  */ 
/********************************************************************/



libname raw 'G:\Data\Rawdata\707677\';

libname common 'G:\Data\Workdata\707677\Common\01Data\01SAS';





/*************/
/* Load data */
/*************/


data panel;

set common.panel;

keep pnr age time granted pyear aar erhvervsindk_real TIMELON_real AKTIV_real PASSIV_real FORMUE_real KOEJD_real house employed_pstill unemployed_pstill out_of_lf_pstill tilbtot_real disability kontant_real social PANTGAELD_real BANKGAELD_real mortgage_real OBLGAELD_real PRIGALD_real GALDIO_real;   

run;





data panel;

set panel;

rename erhvervsindk_real=erhvervsindk;

rename TIMELON_real=TIMELON; 

rename AKTIV_real=AKTIV; 

rename PASSIV_real=PASSIV; 

rename FORMUE_real=FORMUE; 

rename KOEJD_real=KOEJD; 

rename tilbtot_real=tilbtot; 

rename kontant_real=kontant;   

rename PANTGAELD_real=PANTGAELD; 

rename BANKGAELD_real=BANKGAELD; 

rename mortgage_real=mortgage; 

rename OBLGAELD_real=OBLGAELD; 

rename PRIGALD_real=PRIGALD; 

rename GALDIO_real=GALDIO;

run;




data years;

set panel;

keep time;

run;



proc sort data=years nodupkey;

by time;

run;




/***********************************/
/* Age at opening of investigation */
/***********************************/


data panel;

retain pnr aar age time pyear;

set panel;

run;



data age;

set panel;

keep pnr aar age time pyear;

if aar=pyear;

run;



data age;

set age;

rename age=age_proklama;

run;



data age;

set age;

keep pnr age_proklama;

run;



proc sql;

create table panel as select *

from panel as a left join

age as b on

a.pnr=b.pnr;

quit;



data panel;

retain pnr aar age age_proklama time pyear; 

set panel;

run;




proc sort data=panel;

by granted time pnr;

run;






/*************************************************************/
/* Macro producing mean levels by year for outcome variables */
/*************************************************************/




%macro mlevel(outcome,start,end);



proc summary data=panel;

by granted time;

var &outcome.;

output out=stats

mean= / autoname;

where pyear>=&start. and pyear<=&end. and age_proklama>-1 and age_proklama<999;

run;



data stats;

set stats;

drop _type_ _freq_;

run;



data stats;

set stats;

rename &outcome._Mean=&outcome.; 

run;






data granted0;

set stats;

if granted=0;

drop granted;

run;





data granted0;

set granted0;

rename &outcome.=&outcome._ng; 

run;




data granted1;

set stats;

if granted=1;

drop granted;

run;




data granted1;

set granted1;

rename &outcome.=&outcome._g; 

run;




proc sql;

create table stats as select *

from granted0 as a left join

granted1 as b on

a.time=b.time;

quit;




proc sql;

create table years as select *

from years as a left join

stats as b on

a.time=b.time;

quit;


%mend;





%mlevel(erhvervsindk,1984,2003);

%mlevel(AKTIV,1984,2003);

%mlevel(PASSIV,1984,2003);

%mlevel(FORMUE,1984,2003);

%mlevel(kontant,1984,2003);

%mlevel(social,1984,2003);

%mlevel(KOEJD,1987,2003);

%mlevel(house,1987,2003);

%mlevel(tilbtot,1988,2003);

%mlevel(disability,1988,2003);

%mlevel(employed_pstill,1984,2003);

%mlevel(unemployed_pstill,1984,2003);

%mlevel(out_of_lf_pstill,1984,2003);

%mlevel(timelon,1984,2003);

%mlevel(pantgaeld,1991,2003);

%mlevel(bankgaeld,1991,2003);

%mlevel(oblgaeld,1999,2003);

%mlevel(prigald,1988,2003);

%mlevel(galdio,1988,2003);

%mlevel(mortgage,1988,2003);




/************************/
/* Export data to STATA */
/************************/





proc export data=years outfile= "G:\Data\Workdata\707677\Common\01Data\02STATA\mean_level.dta" replace; 

run;













